package com.atguigu.gmall.product.controller;

import com.atguigu.gmall.common.result.Result;
import com.atguigu.gmall.product.model.BaseCategory1;
import com.atguigu.gmall.product.model.BaseCategory2;
import com.atguigu.gmall.product.model.BaseCategory3;
import com.atguigu.gmall.product.service.BaseCategoryService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * @author XIN
 * 2023/4/16
 */

@RestController
@RequestMapping("/admin/product")
public class BaseCategoryApiController {
	@Autowired
	private BaseCategoryService baseCategoryService;
	
	/**
	 * 	查询所有一级分类列表
	 */
	@GetMapping("/getCategory1")
	public Result getCategory1() {
		List<BaseCategory1> category1 = baseCategoryService.getCategory1();
		return Result.ok(category1);
	}
	
	/**
	 * 查询所有er级分类列表
	 * @param category1Id
	 * @return
	 */
	@GetMapping("/getCategory2/{category1Id}")
	public Result getCategory2(@PathVariable Long category1Id) {
		List<BaseCategory2> baseCategory2s =baseCategoryService.getCategory2(category1Id);
		return Result.ok(baseCategory2s);
	}
	/***
	 * 查询指定二级分类下三级分类列表
	 * @param category2Id
	 * @return
	 */
	@GetMapping("/getCategory3/{category2Id}")
	public Result getCategory3(@PathVariable Long category2Id) {
		List<BaseCategory3> baseCategory3s = baseCategoryService.getCategory3(category2Id);
		return Result.ok(baseCategory3s);
	}
}
